package com.cbwl.eoas.web.controller.appint;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cbwl.eoas.cms.api.eoas.IAppOptionFeedbackService;
import com.cbwl.eoas.cms.model.eoas.AppOptionFeedbackDTO;
import com.cbwl.eoas.cms.util.RequestLogUtil;
import com.cbwl.eoas.common.cache.redis.RedisCache;
import com.cbwl.eoas.common.util.constain.DicDetailConstant;
import com.cbwl.eoas.common.web.Result;
import com.cbwl.eoas.web.framework.annotation.InterceptorUrl;



/**
 * 
 * <p>[描述信息：app意见反馈接口]</p>
 *
 * @author 虞云波 - yuyunbo@3856.cc
 * @version 1.0 Created on 2017年10月12日 下午13:29:23
 */
@RestController
@RequestMapping("/v1/appoption")
public class AppOptionFeedbackController {
	
	//业务层注解
	@Autowired
	private IAppOptionFeedbackService appOptionFeedbackService;
	
	
	@Autowired
	private RedisCache<String,String> redisCache;


	

	/**
	 * 
	 * <p>保存意见反馈信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping(value="/saveAppOption",method = RequestMethod.POST)
	@InterceptorUrl(validsecond=5,validnum=1)
	public Object saveAppOptionFeedback(HttpServletRequest request,AppOptionFeedbackDTO bean,String tokenId) throws Exception {
		
		Result result = new Result(Result.Status.OK, "请求成功", "200");
		if(StringUtils.isEmpty(bean.getAofContext()) || StringUtils.isEmpty(bean.getAofKey()) ){
			result.setCode("CBWL-000010");
			return result;
		}
		bean.setGmtCreate(new Date());
		bean.setAofStatus(DicDetailConstant.aof_status_1);
		String user_id = redisCache.getStr(tokenId);
		bean.setCreater(Long.valueOf(user_id));
	
		 String ua = request.getHeader("User-Agent");
		 bean.setAofRestype(RequestLogUtil.getTypeByAgent(ua));
		
		appOptionFeedbackService.saveObject(bean);
		 
		return result;
	}




}
